<?php
class Apply extends AppModel {

    var $name = 'Apply';
    
    function saveApply($data){
        return $this->save($data);
    }
    
    function fGetListMyApplied($i_LocumId)
    {
         return $this->find('all',array('joins' => array(
                                                                          array(
                                                                              'table' => 'vacancies',
                                                                              'alias' => 'Vacancy',
                                                                              'type' => 'inner',
                                                                              'conditions'=> array('Apply.vacancy_id = Vacancy.id')
                                                                              )),'fields'=>array('Apply.*,Vacancy.title'),'conditions'=>array('Apply.locum_id'=>$i_LocumId)));
    }
    
   function fGetListMyAppliedByVacancyId($a_VacancyId)
    {
         return $this->find('all',array('joins' => array(
                                                                          array(
                                                                              'table' => 'vacancies',
                                                                              'alias' => 'Vacancy',
                                                                              'type' => 'inner',
                                                                              'conditions'=> array('Apply.vacancy_id = Vacancy.id')
                                                                              )),'fields'=>array('Apply.*,Vacancy.title'),'conditions'=>array('Apply.vacancy_id '=>explode(',',$a_VacancyId))));
    }
    
    
    function fGetListMyAppliedByApplyId($i_ApplyId)
    {
         return $this->find('first',array('joins' => array(
                                                                          array(
                                                                              'table' => 'users',
                                                                              'alias' => 'Locum',
                                                                              'type' => 'inner',
                                                                              'conditions'=> array('Apply.locum_id = Locum.id')
                                                                              )),'fields'=>array('Apply.*,Locum.*'),'conditions'=>array('Apply.id'=>$i_ApplyId)));
    }
    
    
function fGetListLocumAppliedByApplyId($i_ApplyId)
    {
         return $this->find('first',array('joins' => array(
                                                                          array(
                                                                              'table' => 'users',
                                                                              'alias' => 'Locum',
                                                                              'type' => 'inner',
                                                                              'conditions'=> array('Apply.locum_id = Locum.id')
                                                                              ),
                                                                              array(
                                                                              'table' => 'vacancies',
                                                                              'alias' => 'Vacancy',
                                                                              'type' => 'inner',
                                                                              'conditions'=> array('Apply.vacancy_id = Vacancy.id')
                                                                              )
                                                                              ),'fields'=>array('Apply.*,Locum.*,Vacancy.*'),'conditions'=>array('Apply.id'=>$i_ApplyId)));
    }
    
    function applideDateRage($i_ApplyId)
    {
        return $this->find('first',array('conditions'=>array('Apply.id'=>$i_ApplyId)));
    }
    
    function fGetListAppliedByPharmacyId($i_PharmacyId)
    {
         return $this->find('all',array('joins' => array(
                                                                          array(
                                                                              'table' => 'users',
                                                                              'alias' => 'Locum',
                                                                              'type' => 'inner',
                                                                              'conditions'=> array('Apply.locum_id = Locum.id')
                                                                              ),
                                                                              array(
                                                                              'table' => 'vacancies',
                                                                              'alias' => 'Vacancy',
                                                                              'type' => 'inner',
                                                                              'conditions'=> array('Apply.vacancy_id = Vacancy.id')
                                                                              )
                                                                              ),'fields'=>array('Apply.*,Locum.*,Vacancy.*'),'conditions'=>array('Apply.id'=>$i_ApplyId)));
    }
}
?>